//
//  AFNIsnetWorkingTool.m
//  TakeYouTourTogether
//
//  Created by dllo on 15/11/28.
//  Copyright © 2015年 king. All rights reserved.
//

#import "AFNIsnetWorkingTool.h"

@implementation AFNIsnetWorkingTool

#pragma mark 创建单例网络检测
+ (instancetype)sharedIsNetworking {
    static AFNIsnetWorkingTool *sharedSingle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedSingle = [[AFNIsnetWorkingTool alloc]init];
    });
    
    return sharedSingle;
}

+ (void)isnetWorking{
    //检测网络
   AFNIsnetWorkingTool *sharedSingle = [[AFNIsnetWorkingTool alloc] initWithBaseURL:[NSURL URLWithString:@"www.baidu.com"]];
    sharedSingle.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
    [sharedSingle.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN:
            {
                NSLog(@"------WWAN------");
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:LanguageTool(@"提示") message:LanguageTool(@"连接3G网络") delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
                [alert show];
                [alert dismissWithClickedButtonIndex:0 animated:YES];

            } break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
            {
                NSLog(@"------WiFi------");
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:LanguageTool(@"提示") message:LanguageTool(@"已连接WiFi") delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
                [alert show];
                [alert dismissWithClickedButtonIndex:0 animated:YES];
            } break;
            case AFNetworkReachabilityStatusNotReachable:
            {
                NSLog(@"------NotReachable------");
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:LanguageTool(@"提示") message:LanguageTool(@"未连接网络") delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
                [alert show];
                [alert dismissWithClickedButtonIndex:0 animated:YES];

            }break;
            default:
                break;
        }
    }];
    [sharedSingle.reachabilityManager startMonitoring];
}
@end
